<?php

require_once 'DB.class.php';

class Item {


	public $i_itemcode;
	public $i_regdate;
	public $i_remark;
	public $i_itemcolor;
	public $i_itemtype;
	
	
	//Constructor is called whenever a new object is created.
	//Takes an associative array with the DB row as an argument.
	function __construct($data) {
		$this->i_itemcode = (isset($data['i_itemcode'])) ? $data['i_itemcode'] : "";
		$this->i_regdate = (isset($data['i_regdate'])) ? $data['i_regdate'] : "";
		$this->i_remark = (isset($data['i_remark'])) ? $data['i_remark'] : "";
		$this->i_itemcolor = (isset($data['i_itemcolor'])) ? $data['i_itemcolor'] : "";
		$this->i_itemtype = (isset($data['i_itemtype'])) ? $data['i_itemtype'] : "";
	}

	public function save($isNewData = false) {
		//create a new database object.
		$db = new DB();

		//if the user is already registered and we're
		//just updating their info.
		if(!$isNewData) {
			//set the data array
			$data = array(
				"i_itemcode" => "'$this->i_itemcode'",
				"i_regdate" => "'$this->i_regdate'",
				"i_remark" => "'$this->i_remark'",
				"i_itemcolor" => "'$this->i_itemcolor'",
				"i_itemtype" => "'$this->i_itemtype'",
			);

			//update the row in the database
			$db->update($data, 'itemcode', 'i_itemcode = '.$this->i_itemcode);
		}else {
		//if the user is being registered for the first time.
			$data = array(
				"i_itemcode" => "'$this->i_itemcode'",
				"i_regdate" => "'$this->i_regdate'",
				"i_remark" => "'$this->i_remark'",
				"i_itemcolor" => "'$this->i_itemcolor'",
				"i_itemtype" => "'$this->i_itemtype'",
			);

			$this->i_itemcode = $db->insert($data, 'itemcode');
		}
		return true;
	}
	
	public function remove($id) {
			mysql_query("DELETE FROM  `itemcode` WHERE  `i_itemcode` =  '$id'");
	}
	
	public function UpdateItem($i_itemcode,$i_itemcolor,$i_itemtype){
		
		$result = mysql_query("UPDATE  `laundrybox`.`itemcode` SET  `i_itemcolor` =  '".$i_itemcolor."' WHERE  `itemcode`.`i_itemcode` =".$i_itemcode." AND  `itemcode`.`i_itemtype` =  '".$i_itemtype."' AND  `itemcode`.`i_itemcolor` =  'Choose a Color' AND  `itemcode`.`i_remark` =  '<p> </p>' LIMIT 1 ;");
	}
}

?>